<?php

namespace App\Http\Controllers\User;

use App\Helpers\ResponseData;
use App\Http\Controllers\Controller;
use App\Models\Divide\DepartmentSplitRatio;
use App\Models\Divide\PdUserRelationship;
use Illuminate\Http\Request;

class UserController extends Controller
{
    //
    use ResponseData;
//    获取用户数据
    public function getUser(PdUserRelationship $model,Request $request){
        if(!$request->filled('system_id')){
            return $this->failed('请传递品类id',201);
        }
        $department_arr = DepartmentSplitRatio::query()
            ->where('system_id',$request->system_id)
            ->pluck('user_id');

        $model = $model->select('uid','name','id')
            ->where('role',3);
        if($department_arr->count()>0){
            $model = $model->whereNotIn('id',$department_arr);
        }
        if($request->filled('name')){
            $model = $model->where('name','like','%'.$request->name.'%');
        }
        $data = $model->get();
        return $this->success($data);
    }
}
